package com.dhcc.sdc.cdss.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.sdc.cdss.entity.SdcCdssLabEntity;
import com.dhcc.sdc.cdss.service.ISdcCdssLabService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 *
 *
 * @ClassName: SdcCdssLabController
 * @Description: TODO
 * @author zhangdc
 * @date 2022-06-23 15:05:47
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdccdsslab")
public class SdcCdssLabController extends BaseController {

    private String PREFIX = "/backend/sds/sdccdsslab/";

    @Autowired
    private ISdcCdssLabService sdcCdssLabService;

    /**
     * 获取列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
        Page<SdcCdssLabEntity> page = new PageFactory<SdcCdssLabEntity>().defaultPage();
        List<SdcCdssLabEntity> result = this.sdcCdssLabService.page(page,params);
        page.setRecords((List<SdcCdssLabEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdcCdssLabEntity sdcCdssLab) {
        if (CommonUtil.isOneEmpty(sdcCdssLab)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdcCdssLab.insert();
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdcCdssLabId) {

        this.sdcCdssLabService.deleteById(sdcCdssLabId);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdcCdssLabEntity sdcCdssLab) {
        if (CommonUtil.isOneEmpty(sdcCdssLab)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdcCdssLabEntity old = this.sdcCdssLabService.selectById(sdcCdssLab.getId());

        old.setItemId(sdcCdssLab.getItemId());
        old.setQcentityId(sdcCdssLab.getQcentityId());
        old.setItemName(sdcCdssLab.getItemName());
        old.setItemDesc(sdcCdssLab.getItemDesc());
        old.setSourceFlag(sdcCdssLab.getSourceFlag());
        old.updateAllColumnById();
        return R.ok();
    }
}
